package config

import (
	"encoding/json"
	"os"
)

var (
	LogoDir          = "logo"
	ItemDir          = "item"
	CertificationDir = "certification"
)

type Config struct {
	DSN        string `json:"dsn"`
	Host       string `json:"host"`
	Port       string `json:"port"`
	RPCAddress string `json:"rpcAddress"`
	Key        string `json:"key"`
	Auth       string `json:"auth"`
	Contract   string `json:"contract"`
	TempDir    string `json:"tempDir"`
}

func New(path string) (*Config, error) {
	file, err := os.Open(path)
	defer file.Close()
	if err != nil {
		return nil, err
	}
	decoder := json.NewDecoder(file)
	config := &Config{}
	err = decoder.Decode(config)
	if err != nil {
		return nil, err
	}
	return config, nil
}

func Test() *Config {
	return &Config{
		DSN:        "root:123456@tcp(127.0.0.1:3306)/aqchain?charset=utf8mb4&parseTime=True&loc=Local",
		Host:       "127.0.0.1",
		Port:       "8080",
		RPCAddress: "ws://127.0.0.1:8551",
		Key:        "/home/ganyu/go/src/github.com/aqchain/build/bin/node1/keystore/UTC--2021-04-01T07-30-59.840294326Z--fc97a1a683fb0108299d5725bc9d72899c9a86b4",
		Auth:       "123456",
		Contract:   "0xB28BeC7ab0E007AE4Ad371Da51eF39F54719Be6A",
		TempDir:    "/temp",
	}
}
